package polymorphic;

// 多态
public class override {
    public static void main(String[] args) {
        // 给一个有普通收入、工资收入和享受国务院特殊津贴的小伙伴算税: 3000 7500 15000
        Income[] incomes = {
                new Income(3000),
                new Wage(7500),
                new SpecialAllowancesOfTheStateCouncil(15000),
        };
        double result = 0.0;
        for (Income income : incomes) {
            result += income.getIncome();
        }
        System.out.println(result);
    }
}

//普通收入 0.1
class Income {
    protected double income;

    public Income(double income) {
        this.income = income;
    }

    public double getIncome() {
        return income * 0.1;
    }
}

// 工资收入 <= 500 ? 0 : (收入- 500) * 0.2
class Wage extends Income {
    public Wage(double income) {
        super(income);
    }

    @Override
    public double getIncome() {
        if (income <= 5000) {
            return 0;
        }
        return (income - 5000) * 0.2;
    }
}

// 国务院特殊津贴: 0
class SpecialAllowancesOfTheStateCouncil extends Income {
    public SpecialAllowancesOfTheStateCouncil(double income) {
        super(income);
    }

    @Override
    public double getIncome() {
        return 0;
    }
}
